## Replication Material 
# Article: "Agenda Control and Timing of Bill Initiation:  A Temporal Perspective on Coalition Governance in Parliamentary Democracies
# Authors: Thomas König, Nick Lin, Xiao Lu, Thiago N. Silva, Nikoleta Yordanova, and Galina Zudenkova
# The American Political Science Review
# 2021
 
## Packages
library(circglmbayes)
library(gmodels)
library(dplyr)
library(ggplot2)   
library(ggthemes)
library(stargazer)
library(glue)
library(gridExtra)
library(coda)
library(lubridate)
# library(devtools)
# install_github("jokergoo/ComplexHeatmap")
library(ComplexHeatmap)
library(gridBase)
library(circlize)

## Load in data
load("./main_circular_data.RData")

## Figure 2. Relative Timing and Number of Government Bills within Terms 
pdf("./Figures/Fig2.pdf",width = 10,height = 8)
ggplot(main_circular, aes(x = raw_bill_location)) + 
  geom_histogram(breaks = c(0,0.5*pi,pi,1.5*pi,2*pi), colour = "grey") + 
  coord_polar(start = 0) + theme_minimal() + 
  # scale_x_continuous("", limits = c(0, 2*pi), breaks = c(0,0.5*pi,pi,1.5*pi), labels = c("0%","25%","50%","75%") )+
  scale_x_continuous("", limits = c(0, 2*pi), breaks = c(0,0.5*pi,pi,1.5*pi), labels = c("Government start",
                                                                                         "1/4",
                                                                                         "1/2 term",
                                                                                         "3/4") )+
  facet_wrap(~country)+
  ylab("Number of Government Bills")
dev.off()


## Table 1.  Variables and Descriptive Statistics
stargazer(main_circular[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                          "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                          "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))


## Table 2. 
## The Effects of Experienced Scrutiny, Coalition Policy Divergence, and 
## Powerful Ministers on Timing of Bill Initiation 

# Model 1 (Hypothesis 1)
set.seed(2345)
model_1 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                     policy_saliency + minister_party_size + opposition_conflict + 
                     government_duration, 
                   data = main_circular, Q = 100000, burnin = 1000)
print(model_1)


# Model 2 (Hypothesis 2)
set.seed(2345)
model_2 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                     policy_saliency + minister_party_size + opposition_conflict + government_duration +
                     coalition_policy_divergence*experienced_scrutiny, 
                   data = main_circular, Q = 100000, burnin = 1000)
print(model_2)


# Model 3 (Hypothesis 3)
set.seed(2345)
model_3 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                     policy_saliency + minister_party_size + opposition_conflict + government_duration +
                     minister_median_party +
                     experienced_scrutiny*minister_party_size*minister_median_party, 
                   data = main_circular, Q = 100000, burnin = 1000)
print(model_3)


## Figure 3.  The Effect of Experienced Scrutiny on the Timing of Bill Initiation
b0s = model_1$b0_chain
kps = model_1$kp_chain
bcs = model_1$bt_chain
bds = model_1$dt_chain
df = main_circular
df$sector = as.factor(1) 
mu_pred_fun = function(beta0,beta_d,x_d = NULL,beta_c,x_c){
  vpi = 3.1415926
  if (is.null(x_d)){
    mu = beta0 + 2*atan( x_c %*% beta_c )    
  } else{
    mu = beta0 +x_d %*% beta_d + 2*atan( x_c %*% beta_c )    
  }
  return(mu)
}
dfsim = df[1:500,]
dfsim = subset(dfsim, select = c(
  sector,raw_bill_location,
  experienced_scrutiny,  coalition_policy_divergence, policy_saliency,  
  minister_party_size, opposition_conflict, government_duration
))
N = dim(dfsim)[1]
dfsim$coalition_policy_divergence = 0
dfsim$experienced_scrutiny = seq(0,60,length.out = N )
dfsim$policy_saliency = 0
dfsim$opposition_conflict = 0
dfsim$minister_party_size = 0
dfsim$government_duration = 0
xc = as.matrix(dfsim[,-c(1,2)])
mus = mu_pred_fun(beta0 = 0, beta_c = t(bcs), beta_d = NULL, x_c = xc, x_d = NULL)
lub = apply(mus,1,quantile,probs=c(0.025,0.5,0.975))
lub = t(lub)
x1 = dfsim$coalition_policy_divergence
lub1 = lub
nn = 100
aux_line_x = seq(0,3.14159*2, length.out = nn)
aux_line_y = cbind(rep(0,nn),
                   rep(20,nn),
                   rep(40,nn),
                   rep(60,nn))
nnn = 4
aux_line2_x = cbind(rep(3.1415926/2,nnn),
                    rep(3.1415926,nnn),
                    rep(3.1415926/2*3,nnn)
)
aux_line2_y = seq(0,60,length.out = nnn)
pdf("./Figures/Fig3.pdf", width = 7,height = 7)
circos.clear()
circos.par("track.height" = 0.8,start.degree = 90,gap.degree = 0)
circos.initialize(factors = dfsim$sector, x = dfsim$raw_bill_location, xlim = c(0,3.14159*2))
circos.track(factors = dfsim$sector, y = dfsim$experienced_scrutiny,
             panel.fun = function(x, y) {
               circos.axis(labels.cex = 1.7,
                           major.at = c(0,1.570796,3.141593,4.712389), 
                           labels = c("0%","","50%",""))
             })
circos.lines(aux_line_x,aux_line_y[,1],col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(aux_line_x,aux_line_y[,2],col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(aux_line_x,aux_line_y[,3],col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(aux_line_x,aux_line_y[,4],col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(aux_line2_x[,1],aux_line2_y,col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(aux_line2_x[,2],aux_line2_y,col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(aux_line2_x[,3],aux_line2_y,col = "#999999",track.index = 1,lwd = 0.2)
d1 = c(dfsim$experienced_scrutiny,rev(dfsim$experienced_scrutiny))
d2 = c(lub[,1],rev(lub[,3]))
circos.polygon(d2, d1, col = "blue", border = NA)
circos.lines(lub[,2], dfsim$experienced_scrutiny, col = "gray90",track.index = 1)
circos.yaxis("left", labels.cex = 1.5)
circos.text(0.8, 30, "Exp. Scrutiny", facing = "down", 
            adj = c(0.5, 0), cex = 2.0)
circos.axis("bottom",direction = "inside",labels.cex = 1.2,
            major.at = c(0,1.570796,3.141593,4.712389), 
            labels = c("0%","25%","50%","75%"))
lgd_lines = Legend(at = c("Temporal location (95% CI)"), type = "lines",
                   legend_gp = gpar(col = c("blue"), lwd = 5), title_position = "topleft",
                   title = "",labels_gp = gpar(fontsize = 19),size = unit(4,"mm"),grid_height = unit(7,"mm"))
lgd_list_horizontal = packLegend(lgd_lines,direction = "horizontal")
draw(lgd_list_horizontal , x = unit(5,"cm"), y = unit(3, "cm"), just = c("left"))
dev.off()


## Figure 4.  Marginal Effects of Experienced Scrutiny on Bill Initiation Timing,
## Conditional on Coalition Policy Divergence
b0s = model_2$b0_chain
kps = model_2$kp_chain
bcs = model_2$bt_chain
bds = model_2$dt_chain
apply(bcs,2,mean)
div_coef = bcs[,2]
scr_coef = bcs[,1]
div_scr_coef = bcs[,7]
N = 100
sim_div = seq(0,10,length.out = N)
store_matrix1 = matrix(NA, nrow = dim(bcs)[1], ncol = N)
for (i in 1:N){
  store_matrix1[,i] = scr_coef + div_scr_coef * sim_div[i]
}
margin_effect2 = as.data.frame(t(apply(store_matrix1,2,quantile, probs = c(0.025,0.5,0.975))))
names(margin_effect2) = c("lower","median","upper")
margin_effect2$x = sim_div
temp_dat =  as.data.frame(main_circular$coalition_policy_divergence[which(main_circular$coalition_policy_divergence<=10)])
names(temp_dat) = "x"
pdf("./Figures/Fig4.pdf", width = 7,height = 7)
ggplot(margin_effect2, aes(x)) +
  geom_ribbon(aes(ymin = lower*500,ymax=upper*500),alpha = 0.4)+
  geom_line(aes(y=median*500),col = "white")+
  theme_bw()+
  ylab(" Marginal Effects of Experienced Scrutiny")+
  xlab("Coalition Policy Divergence") +
  geom_histogram(data = temp_dat,alpha = 0.2) +
  scale_y_continuous(breaks = c(0,1250,2500,5000), labels = c(0,2.5,5,10))+
  theme(legend.position="bottom",legend.title = element_blank())
dev.off()


## Figure 5.  Marginal Effects of Experienced Scrutiny on the Timing of Bill Initiation,
## Conditional on the Minister’s Party Size and Minister Median Party
b0s = model_3$b0_chain
kps = model_3$kp_chain
bcs = model_3$bt_chain
bds = model_3$dt_chain
scr_coef = bcs[,1]
size_coef = bcs[,4]
scr_size_coef = bcs[,7]
scr_median_coef = bcs[,8]
size_median_coef = bcs[,9]
scr_size_median_coef = bcs[,10]
median_coef = bds
N = 100
sim_seat = seq(0,0.6,length.out = N)
store_matrix1 = matrix(NA, nrow = dim(bcs)[1], ncol = N)
for (i in 1:N){
  store_matrix1[,i] = scr_coef + scr_size_coef * sim_seat[i]
}
margin_effect1 = as.data.frame(t(apply(store_matrix1,2,quantile, probs = c(0.025,0.5,0.975))))
names(margin_effect1) = c("lower","median","upper")
margin_effect1$x = sim_seat
store_matrix2 = matrix(NA, nrow = dim(bcs)[1], ncol = N)
for (i in 1:N){
  store_matrix2[,i] = scr_coef + scr_size_coef * sim_seat[i] + scr_median_coef + scr_size_median_coef * sim_seat[i] + median_coef
}
margin_effect2 = as.data.frame(t(apply(store_matrix2,2,quantile, probs = c(0.025,0.5,0.975))))
names(margin_effect2) = c("lower","median","upper")
margin_effect2$x = sim_seat
margin_effect1$type = "Minister Party Median = 0"
margin_effect2$type = "Minister Party Median = 1"
margin_effect = rbind(margin_effect1,margin_effect2)
temp_dat =  as.data.frame(main_circular$minister_party_size[which(main_circular$minister_party_size<=0.6)])
names(temp_dat) = "x"
temp_dat$median = 1
pdf("./Figures/Fig5.pdf",width = 7,height = 7)
ggplot(margin_effect, aes(x)) +
  geom_ribbon(aes(ymin = lower*2000,ymax=upper*2000,linetype = type),alpha = 0.4)+
  geom_line(aes(y=median*2000,linetype = type),col = "white")+
  theme_bw()+
  ylab(" Marginal Effects of Experienced Scrutiny")+
  xlab("Minister's Size (Seat Share)") +
  geom_histogram(data = temp_dat,alpha = 0.2) +
  scale_y_continuous(breaks = c(-1000,0,1000,2000,3000), labels = c(-0.5,0,0.5,1,1.5))+
  theme(legend.position="bottom",legend.title = element_blank())
dev.off()


## Supplementary Material ##

## Appendix E. Descriptive Statistics, Passage Rate, and Experienced Scrutiny
# Table E1.  Overall Passage Rate
CrossTable(main_circular$passage)

# Table E2.  Number of Proposals by Country
# Table E3.  Passage Rates by Country
CrossTable(main_circular$country, main_circular$passage)


# Figure E1.  Distribution of the VariableExperienced Scrutinyby Country
plot_duration_all  <- ggplot(main_circular, aes(x=experienced_scrutiny)) + 
  geom_histogram(aes(y=..count..), 
                 color="black", fill="lightgray", bins = 100) + theme_few()  + 
  ylab("Count") + xlab("Experienced Scrutiny (Days)") + 
  geom_vline(aes(xintercept=median(experienced_scrutiny)), 
             color="blue", size=0.7, linetype="dashed") + 
  scale_x_continuous(breaks=seq(0, 500, 50)) + 
  ggtitle("All Countries (Dashed blue line = Median value)") +
  theme(axis.text.y = element_text(size = 8),
        axis.text.x = element_text(size = 8),
        axis.title.y = element_text(size = 9),
        axis.title.x = element_text(size = 9),
        plot.title = element_text(size = 10, face = "bold")) 

plots_duration = list()
list_do_call_all = list()
unique_country = unique(sort(main_circular$country))

for(i in unique_country) {
  plots_duration[[i]] <-main_circular%>% 
    filter(country == i) %>% 
    group_by(country) %>% 
    ggplot(aes(x=experienced_scrutiny)) + 
    geom_histogram(aes(y=..count..),
                   color="black", fill="lightgray", bins = 100) + theme_few()  +
    ylab("Count") + xlab("Experienced Scrutiny (Days)") +
    geom_vline(aes(xintercept=median(experienced_scrutiny)), 
               color="blue", size=0.7, linetype="dashed") +
    scale_x_continuous(breaks=seq(0, 500, 50)) +
    theme(axis.text.y = element_text(size = 8),
          axis.text.x = element_text(size = 8),
          axis.title.y = element_text(size = 9),
          axis.title.x = element_text(size = 9),
          plot.title = element_text(size = 10)) +
    ggtitle(glue("{i}")) 
  
  list_do_call_all[[i]] = grid.arrange(plots_duration[[i]])
  
}

pdf(file = "./Figures/FigE1.pdf",
    width = 9, height = 13) # The height of the plot in inches
grid.arrange(plot_duration_all, plots_duration[[1]], plots_duration[[2]],  plots_duration[[3]],
             plots_duration[[4]], plots_duration[[5]],  plots_duration[[6]],  
             plots_duration[[7]], plots_duration[[8]],  plots_duration[[9]],
             plots_duration[[10]], plots_duration[[11]], ncol=2)
dev.off()


## Descriptive Statistics by Country
# Table E4.  Descriptive Statistics:  Belgium
stargazer(subset(main_circular, main_circular$country=="Belgium")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                    "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                    "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E5.  Descriptive Statistics:  Czech Republic
stargazer(subset(main_circular, main_circular$country=="Czech Republic")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                           "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                           "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E6.  Descriptive Statistics:  Denmark
stargazer(subset(main_circular, main_circular$country=="Denmark")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                    "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                    "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E7.  Descriptive Statistics:  Estonia
stargazer(subset(main_circular, main_circular$country=="Estonia")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                    "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                    "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E8.  Descriptive Statistics:  Finland
stargazer(subset(main_circular, main_circular$country=="Finland")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                    "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                    "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E9.  Descriptive Statistics:  Germany
stargazer(subset(main_circular, main_circular$country=="Germany")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                    "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                    "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E10.  Descriptive Statistics:  Hungary
stargazer(subset(main_circular, main_circular$country=="Hungary")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                    "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                    "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E11.  Descriptive Statistics:  Latvia
stargazer(subset(main_circular, main_circular$country=="Latvia")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                   "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                   "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E12.  Descriptive Statistics:  The Netherlands
stargazer(subset(main_circular, main_circular$country=="Netherlands")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                        "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                        "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E13.  Descriptive Statistics:  Norway
stargazer(subset(main_circular, main_circular$country=="Norway")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                   "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                   "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))

# Table E14.  Descriptive Statistics:  Poland
stargazer(subset(main_circular, main_circular$country=="Poland")[c("raw_bill_location", "experienced_scrutiny", "coalition_policy_divergence", 
                                                                   "raw_pol_saliency", "minister_party_size", "opposition_conflict", "government_duration",
                                                                   "minister_median_party")], 
          covariate.labels = c("Bill Temporal Location", "Experienced Scrutiny",  
                               "Coalition Policy Divergence", "Policy Saliency", 
                               "Minister's Party Size", 
                               "Opposition Policy Divergence", 
                               "Government Duration", "Minister Median Party"),
          type = "text", digits=2, 
          summary.stat = c("mean", "sd", "min", "max", "n"))


## Appendix F. A Brief Introduction to Circular Regression
# Figure F1
circular <- main_circular
circular$bill_location <- circular$raw_bill_location
df = circular
df$sector = as.factor(1) 
nn = 100
aux_line_x = seq(0,3.14159*2, length.out = nn)
aux_line_y = cbind(rep(0,nn),
                   rep(100,nn),
                   rep(200,nn),
                   rep(300,nn),
                   rep(400,nn))
nnn = 5
aux_line2_x = cbind(rep(3.1415926/2,nnn),
                    rep(3.1415926,nnn),
                    rep(3.1415926/2*3,nnn)
)
aux_line2_y = seq(0,500,length.out = nnn)
pdf("./Figures/FigF1.pdf",width = 7,height = 7)
circos.clear()
circos.par("track.height" = 0.1,start.degree = 90,gap.degree = 0)
circos.initialize(factors = df$sector, x = df$bill_location, xlim = c(0,3.14159*2))
circos.track(factors = df$sector, y = df$experienced_scrutiny ,
             panel.fun = function(x, y) {
               circos.axis(labels.cex = 1.5,
                           major.at = c(0,1.570796,3.141593,4.712389), 
                           labels = c("0%","25%","50%","75%"))
             })
circos.trackPoints(df$sector, df$bill_location, df$experienced_scrutiny, pch = 16, cex = 1,col = "#999999")
circos.trackHist(df$sector, df$bill_location, bin.size = 0.2,col = "#999999")
circos.trackPlotRegion(ylim = range(df$experienced_scrutiny), track.height = 0.5, panel.fun = function(x, y) {
  x1 = df$bill_location
  y1 = df$experienced_scrutiny
  or = order(y1,decreasing = F)
  x1 = x1[or]
  y1 = y1[or]
  loess.fit = loess(x1 ~ y1)
  loess.predict = predict(loess.fit, y1, se = TRUE)
  d1 = c(y1, rev(y1))
  d2 = c(loess.predict$fit + loess.predict$se.fit,
         rev(loess.predict$fit - loess.predict$se.fit))
  circos.polygon( d2,d1, col = "#CCCCCC", border = NA)
  circos.points(x1, y1, cex = 0.5,col="#999999")
  circos.lines( loess.predict$fit , y1)
})
circos.yaxis("left", labels.cex = 1.5)
circos.text(0.4, 300, "Duration", facing = "down", 
            adj = c(0.5, 0), cex = 2.5)
circos.axis("bottom",direction = "inside",labels.cex = 1.5, 
            major.at = c(0,1.570796,3.141593,4.712389),
            labels = c("0%","25%","50%","75%")
)
circos.lines(aux_line_x,aux_line_y[,1],col = "#999999",lwd = 0.2)
circos.lines(aux_line_x,aux_line_y[,2],col = "#999999",lwd = 0.2)
circos.lines(aux_line_x,aux_line_y[,3],col = "#999999",lwd = 0.2)
circos.lines(aux_line_x,aux_line_y[,4],col = "#999999",lwd = 0.2)
circos.lines(aux_line_x,aux_line_y[,5],col = "#999999",lwd = 0.2)
circos.lines(aux_line2_x[,1],aux_line2_y,col = "#999999",lwd = 0.2)
circos.lines(aux_line2_x[,2],aux_line2_y,col = "#999999",lwd = 0.2)
circos.lines(aux_line2_x[,3],aux_line2_y,col = "#999999",lwd = 0.2)
dev.off()

# Figure F2
x = rnorm(100)
b = 2
y = 2* atan(x*b)
set.seed(3425)
dat = as.data.frame(cbind(x,y))
modlm = lm(y~x, dat)
summary(modlm)
y_lm = predict(modlm)
dat1 = dat
dat1$y_lm = y_lm
dat1$y = dat1$y + pi
dat1$y_lm = dat1$y_lm +pi
dat1$y_lm = ifelse(dat1$y_lm>2*pi, dat1$y_lm - 2*pi, dat1$y_lm)
dat1$y_lm = ifelse(dat1$y_lm<0, dat1$y_lm + 2*pi, dat1$y_lm)
nn = 100
aux_line_x = seq(0,3.14159*2, length.out = nn)
aux_line_y = cbind(rep(0,nn),
                   rep(0.5,nn),
                   rep(1,nn),
                   rep(1.5,nn),
                   rep(2.0,nn))
nnn = 5
aux_line2_x = cbind(rep(3.1415926/2,nnn),
                    rep(3.1415926,nnn),
                    rep(3.1415926/2*3,nnn)
)
aux_line2_y = seq(-3,3,length.out = nnn)
dfsim = dat1
dfsim$sector = 1
dfsim = dfsim[order(dfsim$x),]
pdf("./Figures/FigF2.pdf", width = 7,height = 7)
circos.clear()
circos.par("track.height" = 0.8,start.degree = 90,gap.degree = 0)
circos.initialize(factors = dfsim$sector, x = dfsim$y, xlim = c(0,3.14159*2))
circos.track(factors = dfsim$sector, y = dfsim$x,
             panel.fun = function(x, y) {
               circos.axis(labels.cex = 1.7,
                           major.at = c(0,1.570796,3.141593,4.712389), 
                           labels = c("0%","","50%",""))
             })
circos.lines(aux_line2_x[,1],aux_line2_y,col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(aux_line2_x[,2],aux_line2_y,col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(aux_line2_x[,3],aux_line2_y,col = "#999999",track.index = 1,lwd = 0.2)
circos.lines(dfsim$y, dfsim$x, col = "black",track.index = 1,lwd = 3)
circos.lines(dfsim$y_lm, dfsim$x, col = "gray",track.index = 1,lwd = 3,lty = "dashed")
circos.yaxis("left", labels.cex = 1.5)
circos.text(0.4, 0, "X", facing = "down", 
            adj = c(1, 0), cex = 2.0)
circos.axis("bottom",direction = "inside",labels.cex = 1.2,
            major.at = c(0,1.570796,3.141593,4.712389), 
            labels = c("0%","25%","50%","75%"))
dev.off()



## Appendix G. Convergence Diagnostics

# Table G1.  Heidelberger and Welch’s Convergence Diagnostic for Model 1
heidel.diag(model_1$all_chains, pvalue=0.05) 

# Table G2.  Heidelberger and Welch’s Convergence Diagnostic for Model 2
heidel.diag(model_2$all_chains, pvalue=0.05) 

# Table G3.  Heidelberger and Welch’s Convergence Diagnostic for Model 3
heidel.diag(model_3$all_chains, pvalue=0.05) 

## Table G4.  Main Models with Tuning Parameter at 0.8
# Model 1 (Hypothesis 1)
set.seed(2345)
tuning_1 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                      policy_saliency + minister_party_size + opposition_conflict + 
                      government_duration, 
                    data = main_circular, Q = 100000, burnin = 1000, 
                    bwb = rep(0.8,ncol(model.matrix(bill_temporal_location ~ experienced_scrutiny + 
                                                      coalition_policy_divergence + policy_saliency + 
                                                      minister_party_size + opposition_conflict + 
                                                      government_duration, main_circular)[, -1, drop = FALSE])))
print(tuning_1)

# Model 2 (Hypothesis 2)
set.seed(2345)
tuning_2 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                      policy_saliency + minister_party_size + opposition_conflict + government_duration +
                      coalition_policy_divergence*experienced_scrutiny, 
                    data = main_circular, Q = 100000, burnin = 1000, 
                    bwb = rep(0.8,ncol(model.matrix(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                                                      policy_saliency + minister_party_size + opposition_conflict + government_duration +
                                                      coalition_policy_divergence*experienced_scrutiny, main_circular)[, -1, drop = FALSE])))
print(tuning_2)

# Model 3 (Hypothesis 3)
set.seed(2345)
tuning_3 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                      policy_saliency + minister_party_size + opposition_conflict + government_duration +
                      minister_median_party +
                      experienced_scrutiny*minister_party_size*minister_median_party, 
                    data = main_circular, Q = 100000, burnin = 1000, 
                    bwb = rep(0.8,ncol(model.matrix(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                                                      policy_saliency + minister_party_size + opposition_conflict + government_duration +
                                                      minister_median_party +
                                                      experienced_scrutiny*minister_party_size*minister_median_party, main_circular)[, -1, drop = FALSE])))
print(tuning_3)

# Table G5.  Heidelberger and Welch’s Convergence Diagnostic for Model 1 of Table G4
heidel.diag(tuning_1$all_chains, pvalue=0.05) 

# Table G6.  Heidelberger and Welch’s Convergence Diagnostic for Model 2 of Table G4
heidel.diag(tuning_2$all_chains, pvalue=0.05) 

# Table G7.  Heidelberger and Welch’s Convergence Diagnostic for Model 3 of Table G4
heidel.diag(tuning_3$all_chains, pvalue=0.05) 


## Appendix H. Endogenous Government Duration
# Table H1.  Ex-ante Government Duration Test 1:Removing One-Year Governments from the Analyses
ex_ante_remove_one_year <-main_circular%>% 
  mutate(one_year_gov = ifelse(government_duration<365, 1, 0)) %>% 
  filter(one_year_gov == 0) %>%
  as.data.frame()

# Model 1 (Hypothesis 1)
set.seed(2345)
ex_ante_remove_one_year_1 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                                       policy_saliency + minister_party_size + opposition_conflict + 
                                       government_duration, 
                                     data = ex_ante_remove_one_year, Q = 100000, burnin = 1000)
print(ex_ante_remove_one_year_1)

# Model 2 (Hypothesis 2)
set.seed(2345)
ex_ante_remove_one_year_2 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                                       policy_saliency + minister_party_size + opposition_conflict + government_duration +
                                       coalition_policy_divergence*experienced_scrutiny, 
                                     data = ex_ante_remove_one_year, Q = 100000, burnin = 1000)
print(ex_ante_remove_one_year_2)

# Model 3 (Hypothesis 3)
set.seed(2345)
ex_ante_remove_one_year_3 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                                       policy_saliency + minister_party_size + opposition_conflict + government_duration +
                                       minister_median_party +
                                       experienced_scrutiny*minister_party_size*minister_median_party, 
                                     data = ex_ante_remove_one_year, Q = 100000, burnin = 1000)
print(ex_ante_remove_one_year_3)


## Table H2. 
## Ex-ante Government Duration Test 2:Fixed-Effects Models with Alternative Measure of Government Duration
ex_ante_fe <-main_circular%>% 
  mutate(government_duration1 = ifelse(government_duration<365, 1, 0)) %>% 
  mutate(government_duration2 = ifelse(government_duration<760, 1, 0)) %>% 
  mutate(government_duration3 = ifelse(government_duration<1095, 1, 0)) %>% 
  mutate(government_duration4 = ifelse(government_duration<1460, 1, 0)) %>% 
  mutate(government_duration5 = ifelse(government_duration<1623, 1, 0)) %>% 
  as.data.frame()

# Model 1 (Hypothesis 1)
set.seed(2345)
ex_ante_fe_1 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                          policy_saliency + minister_party_size + opposition_conflict + 
                          government_duration1 + government_duration2 + government_duration3 + government_duration4, 
                        data = ex_ante_fe, Q = 100000, burnin = 1000)
print(ex_ante_fe_1)

# Model 2 (Hypothesis 2)
set.seed(2345)
ex_ante_fe_2 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                          policy_saliency + minister_party_size + opposition_conflict + 
                          coalition_policy_divergence*experienced_scrutiny +
                          government_duration1 + government_duration2 + government_duration3 + government_duration4, 
                        data = ex_ante_fe, Q = 100000, burnin = 1000)
print(ex_ante_fe_2)

# Model 3 (Hypothesis 3)
set.seed(2345)
ex_ante_fe_3 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                          policy_saliency + minister_party_size + opposition_conflict + 
                          minister_median_party +
                          experienced_scrutiny*minister_party_size*minister_median_party +
                          government_duration1 + government_duration2 + government_duration3 + government_duration4, 
                        data = ex_ante_fe, Q = 100000, burnin = 1000)
print(ex_ante_fe_3)

## Table H3.  Ex-ante Government Duration Test 3:  Prior Information
load("./main_exante_duration_data.RData")

# Model 1 (Hypothesis 1)
set.seed(2345)
ex_ante_predict_1 <- circGLM(bill_location_predict ~ experienced_scrutiny + coalition_policy_divergence + 
                               policy_saliency + minister_party_size + opposition_conflict + 
                               government_duration, 
                             data = dat_predict, Q = 100000, burnin = 1000)
print(ex_ante_predict_1)

# Model 2 (Hypothesis 2)
set.seed(2345)
ex_ante_predict_2 <- circGLM(bill_location_predict ~ experienced_scrutiny + coalition_policy_divergence + 
                               policy_saliency + minister_party_size + opposition_conflict + government_duration +
                               coalition_policy_divergence*experienced_scrutiny, 
                             data = dat_predict, Q = 100000, burnin = 1000)
print(ex_ante_predict_2)

# Model 3 (Hypothesis 3)
set.seed(2345)
ex_ante_predict_3 <- circGLM(bill_location_predict ~ experienced_scrutiny + coalition_policy_divergence + 
                               policy_saliency + minister_party_size + opposition_conflict + government_duration +
                               minister_median_party +
                               experienced_scrutiny*minister_party_size*minister_median_party, 
                             data = dat_predict, Q = 100000, burnin = 1000)
print(ex_ante_predict_3)


## Appendix I. Benchmark Models
# Table I1.  Benchmark Model:  Experienced scrutiny
set.seed(2345)
benchmark_scrutiny = circGLM(bill_temporal_location ~ experienced_scrutiny,
                             data=main_circular,  
                             Q = 100000, burnin = 1000)

print(benchmark_scrutiny)

# Table I2.  Benchmark Model:  Experienced scrutiny × Coalition Policy Divergence
set.seed(2345)
benchmark_scrutiny_divergence = circGLM(bill_temporal_location ~ experienced_scrutiny +
                                          coalition_policy_divergence + 
                                          experienced_scrutiny*coalition_policy_divergence,
                                        data=main_circular,  
                                        Q = 100000, burnin = 1000)

print(benchmark_scrutiny_divergence)

# Table I3.  Benchmark Model:  Powerful Ministers and Timing of Bill Initiation Interactions:  
# Experienced scrutiny × Minister’s Party Size × Minister Median Party
set.seed(2345)
benchmark_minister_power = circGLM(bill_temporal_location ~ experienced_scrutiny + 
                                     minister_party_size + minister_median_party +
                                     experienced_scrutiny*minister_party_size*minister_median_party,
                                   data=main_circular,  
                                   Q = 100000, burnin = 1000)

print(benchmark_minister_power)

## Appendix J. Controls for Government Types, and Fixed-Effect Models
# Table Table J1.  The Effects of Experienced scrutiny, Coalition Policy Divergence, 
# and Powerful Ministers on Timing of Bill Initiation, Adding Controls for 
# Government Types (Minimum Winning Coalition and Minority Government, and 
# Surplus-Party Coalition as the Baseline)

# Model 1 (Hypothesis 1)
set.seed(2345)
model_1_gov_type <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                              policy_saliency + minister_party_size + opposition_conflict +
                              government_duration + mwc + minority, 
                            data = main_circular, Q = 100000, burnin = 1000)
print(model_1_gov_type)

# Model 2 (Hypothesis 2)
set.seed(2345)
model_2_gov_type <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                              policy_saliency + minister_party_size + opposition_conflict + government_duration + mwc + minority + 
                              coalition_policy_divergence*experienced_scrutiny, 
                            data = main_circular, Q = 100000, burnin = 1000)
print(model_2_gov_type)

# Model 3 (Hypothesis 3)
set.seed(2345)
model_3_gov_type <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                              policy_saliency + minister_party_size + opposition_conflict + government_duration + mwc + minority +
                              minister_median_party +
                              experienced_scrutiny*minister_party_size*minister_median_party, 
                            data = main_circular, Q = 100000, burnin = 1000)
print(model_3_gov_type)


## Table J2.  Analyses with Majority Governments Only
majority <- main_circular%>% 
  filter(majority==1) 

# Model 1 (Hypothesis 1)
set.seed(2345)
majority_1 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                        policy_saliency + minister_party_size + opposition_conflict + 
                        government_duration, 
                      data = majority, Q = 100000, burnin = 1000)
print(majority_1)

# Model 2 (Hypothesis 2)
set.seed(2345)
majority_2 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                        policy_saliency + minister_party_size + opposition_conflict + government_duration +
                        coalition_policy_divergence*experienced_scrutiny, 
                      data = majority, Q = 100000, burnin = 1000)
print(majority_2)

# Model 3 (Hypothesis 3)
set.seed(2345)
majority_3 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                        policy_saliency + minister_party_size + opposition_conflict + government_duration +
                        minister_median_party +
                        experienced_scrutiny*minister_party_size*minister_median_party, 
                      data = majority, Q = 100000, burnin = 1000)
print(majority_3)


## Table J3.  Robustness Check (FE Models) 
## The Effect of Experienced Scrutiny on the Timing of Bill Initiation

# Model 1. Experienced Scrutiny FE
# Country FE
set.seed(2345)
scrutiny_cfe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + 
                         government_duration + 
                         as.factor(country),
                       data=main_circular,  
                       Q = 100000, burnin = 1000) 

print(scrutiny_cfe)

# Model 2. Experienced Scrutiny FE
# Government FE
set.seed(2345)
scrutiny_gfe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + 
                         government_duration + 
                         as.factor(gov_term),
                       data=main_circular,  
                       Q = 100000, burnin = 1000) 

print(scrutiny_gfe)

# Model 3. Experienced Scrutiny FE
# Ministerial Area FE
set.seed(2345)
scrutiny_afe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + 
                         government_duration + 
                         as.factor(area13),
                       data=main_circular,  
                       Q = 100000, burnin = 1000) 

print(scrutiny_afe)


## Table J4.  Robustness Check (FE Models)Interaction:  
## Experienced scrutiny × Coalition Policy Divergence

# Model 1. Experienced scrutiny × Coalition Policy Divergence
# Country FE
set.seed(2345)
scrutiny_divergence_cfe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                                    policy_saliency + minister_party_size + opposition_conflict + government_duration +
                                    coalition_policy_divergence*experienced_scrutiny + as.factor(country),
                                  data=main_circular,  
                                  Q = 100000, burnin = 1000) 

print(scrutiny_divergence_cfe)

# Model 2. Experienced scrutiny × Coalition Policy Divergence
# Government FE
set.seed(2345)
scrutiny_divergence_gfe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                                    policy_saliency + minister_party_size + opposition_conflict + government_duration +
                                    coalition_policy_divergence*experienced_scrutiny + as.factor(gov_term),
                                  data=main_circular,  
                                  Q = 100000, burnin = 1000) 

print(scrutiny_divergence_gfe)

# Model 3. Experienced scrutiny × Coalition Policy Divergence
# Ministerial Area FE
set.seed(2345)
scrutiny_divergence_afe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                                    policy_saliency + minister_party_size + opposition_conflict + government_duration +
                                    coalition_policy_divergence*experienced_scrutiny + as.factor(area13),
                                  data=main_circular,  
                                  Q = 100000, burnin = 1000) 

print(scrutiny_divergence_afe)

## Table J5.  Robustness Check (FE Models) Powerful Ministers and Bill Initiation 
## Timing Interactions:  Experienced scrutiny × Minister’s Party Size × Minister Median Party

# Model 1. Experienced scrutiny × Minister’s Party Size × Minister Median Party
# Country FE
set.seed(2345)
powerful_cfe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + government_duration +
                         minister_median_party +
                         experienced_scrutiny*minister_party_size*minister_median_party + 
                         as.factor(country),
                       data=main_circular,  
                       Q = 10000, burnin = 1000) 

print(powerful_cfe)

# Model 2. Experienced scrutiny × Minister’s Party Size × Minister Median Party
# Government FE
set.seed(2345)
powerful_gfe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + government_duration +
                         minister_median_party +
                         experienced_scrutiny*minister_party_size*minister_median_party + 
                         as.factor(gov_term),
                       data=main_circular,  
                       Q = 10000, burnin = 1000) 

print(powerful_gfe)

# Model 3. Experienced scrutiny × Minister’s Party Size × Minister Median Party
# Ministerial Area FE
set.seed(2345)
powerful_afe = circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + government_duration +
                         minister_median_party +
                         experienced_scrutiny*minister_party_size*minister_median_party + 
                         as.factor(area13),
                       data=main_circular,  
                       Q = 10000, burnin = 1000) 

print(powerful_afe)

## Table J6. The Effects of Experienced scrutiny, Coalition Policy Divergence, 
## and Powerful Ministers on Timing of Bill Initiation:  
## Data Including the Zero Values for experienced scrutiny.
load("./circular_zeroes_data.RData")

# Model 1
set.seed(2345)
model_1_zeroes <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                            policy_saliency + minister_party_size + opposition_conflict + 
                            government_duration, 
                          data = circular_zeroes, Q = 100000, burnin = 1000)
print(model_1_zeroes)

# Model 2
set.seed(2345)
model_2_zeroes <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                            policy_saliency + minister_party_size + opposition_conflict + government_duration +
                            coalition_policy_divergence*experienced_scrutiny, 
                          data = circular_zeroes, Q = 100000, burnin = 1000)
print(model_2_zeroes)

# Model 3
set.seed(2345)
model_3_zeroes <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                            policy_saliency + minister_party_size + opposition_conflict + government_duration +
                            minister_median_party +
                            experienced_scrutiny*minister_party_size*minister_median_party, 
                          data = circular_zeroes, Q = 100000, burnin = 1000)
print(model_3)

## Appendix K Alternative Estimation Strategy for the Conditional Effect of Coalition
## Policy Divergence on Bill Initiation Timing

# Figure K1. Marginal Effects of Experienced Scrutiny on the Timing of Bill Initiation,
# Conditional on the Level of Coalition Policy Divergence
bins = quantile(main_circular$coalition_policy_divergence, probs = c(1/3, 2/3))
data=main_circular$coalition_policy_divergence_bin = main_circular$coalition_policy_divergence
main_circular$coalition_policy_divergence_bin[which(main_circular$coalition_policy_divergence >= 0 & main_circular$coalition_policy_divergence <= bins[1])] = "0Low"
main_circular$coalition_policy_divergence_bin[which(main_circular$coalition_policy_divergence > bins[1] & main_circular$coalition_policy_divergence <= bins[2])] = "Middle"
main_circular$coalition_policy_divergence_bin[which(main_circular$coalition_policy_divergence > bins[2])] = "High"
set.seed(2345)
model_20 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence_bin + 
                      policy_saliency + minister_party_size + opposition_conflict + government_duration +
                      coalition_policy_divergence_bin*experienced_scrutiny, data=main_circular, Q = 100000, burnin = 1000)
b0s = model_20$b0_chain
kps = model_20$kp_chain
bcs = model_20$bt_chain
bds = model_20$dt_chain
div_coef_middle = bds[,2]
div_coef_high = bds[,1]
scr_coef = bcs[,1]
div_scr_coef_middle = bcs[,7]
div_scr_coef_high = bcs[,6]
store_matrix_low = scr_coef
store_matrix_middle = div_scr_coef_middle + scr_coef
store_matrix_high = div_scr_coef_high + scr_coef
low_q = quantile(store_matrix_low,probs = c(0.025,0.975))
low_m = mean(store_matrix_low)
middle_q = quantile(store_matrix_middle,probs = c(0.025,0.975))
middle_m = mean(store_matrix_middle)
high_q = quantile(store_matrix_high,probs = c(0.025,0.975))
high_m = mean(store_matrix_high)
margin_effect1 = as.data.frame(
  rbind(c(low_q,low_m),
        c(middle_q,middle_m),
        c(high_q,high_m)
  )
)
names(margin_effect1) = c("low","high","mean")
margin_effect1$diverge = factor(c("Low", "Middle", "High"),levels = c("Low", "Middle", "High"))
pdf("./Figures/FigK1.pdf", width = 7,height = 7)
ggplot(margin_effect1, aes(x=diverge, y=mean)) + 
  geom_line() +
  geom_point()+
  geom_errorbar(aes(ymin=low, ymax=high), width=.2,
                position=position_dodge(0.05))+
  theme_bw()+
  ylab(" Marginal Effects of Experienced Scrutiny")+
  xlab("Coalition Policy Divergence")
dev.off()



## Appendix L. Analysis with Incumbent Coalition Parties
# Table L1.  Robustness Check:  Analyses with Coalition Governments 
# Formed with at Least Two Incumbent Parties
incumbent <- main_circular %>% 
  group_by(country, gov_term) %>%
  filter(least2pty == 1) %>% 
  ungroup() %>% 
  as.data.frame()

# Model 1 (Hypothesis 1)
set.seed(2345)
incumbent_1 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + 
                         government_duration, 
                       data = incumbent, Q = 100000, burnin = 1000)
print(incumbent_1)

# Model 2 (Hypothesis 2)
set.seed(2345)
incumbent_2 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + 
                         coalition_policy_divergence*experienced_scrutiny +
                         government_duration, 
                       data = incumbent, Q = 100000, burnin = 1000)
print(incumbent_2)

# Model 3 (Hypothesis 3)
set.seed(2345)
incumbent_3 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + 
                         minister_median_party +
                         experienced_scrutiny*minister_party_size*minister_median_party +
                         government_duration, 
                       data = incumbent, Q = 100000, burnin = 1000)
print(incumbent_3)

## Appendix M. Testing for Confounding Variables
## Table M1.  Robustness Check 1:  Parliamentary Workload and Financial Crises
load(file = "./Global_Crisis_Data.RData")

# Model 1
set.seed(2345)
dat_econ1_1 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + 
                         government_duration +
                         num_partner + number_previous_bills + currency_crises + banking_crisis, 
                       data = dat_econ1, Q = 100000, burnin = 1000)
print(dat_econ1_1)

# Model 2
set.seed(2345)
dat_econ1_2 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + government_duration +
                         coalition_policy_divergence*experienced_scrutiny +
                         num_partner + number_previous_bills + currency_crises + banking_crisis, 
                       data = dat_econ1, Q = 100000, burnin = 1000)
print(dat_econ1_2)

# Model 3
set.seed(2345)
dat_econ1_3 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + government_duration +
                         minister_median_party +
                         experienced_scrutiny*minister_party_size*minister_median_party +
                         num_partner + number_previous_bills + currency_crises + banking_crisis, 
                       data = dat_econ1, Q = 100000, burnin = 1000)
print(dat_econ1_3)


# Table M2.  Robustness Check 2:  Parliamentary Workload and External Events(Economic Indicators)
load(file = "./econ_long.RData")

# Model 1
set.seed(2345)
dat_econ2_1 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + 
                         government_duration + num_partner + number_previous_bills + 
                         lag_gdp_WB_quartile + lag_inf_WB_quartile, 
                       data = dat_econ2, Q = 100000, burnin = 1000)
print(dat_econ2_1)

# Model 2
set.seed(2345)
dat_econ2_2 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + government_duration +
                         coalition_policy_divergence*experienced_scrutiny + num_partner + number_previous_bills + 
                         lag_gdp_WB_quartile + lag_inf_WB_quartile, 
                       data = dat_econ2, Q = 100000, burnin = 1000)
print(dat_econ2_2)

# Model 3
set.seed(2345)
dat_econ2_3 <- circGLM(bill_temporal_location ~ experienced_scrutiny + coalition_policy_divergence + 
                         policy_saliency + minister_party_size + opposition_conflict + government_duration +
                         minister_median_party +
                         experienced_scrutiny*minister_party_size*minister_median_party + 
                         num_partner + number_previous_bills + 
                         lag_gdp_WB_quartile + lag_inf_WB_quartile, 
                       data = dat_econ2, Q = 100000, burnin = 1000)
print(dat_econ2_3)
